home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 April / macformat-075.iso / Shareware Plus / Applications / Alpha / Tcl / SystemCode / globals.tcl < prev    next >
Encoding:
Text File  |  1999-01-28  |  17.8 KB  |  427 lines  |  [TEXT/ALFA]

  1. ## -*-Tcl-*-
  2.  # ###################################################################
  3.  #  Alpha - new Tcl folder configuration
  4.  # 
  5.  #  FILE: "globals.tcl"
  6.  #                                    created: 13/6/94 {9:39:12 pm} 
  7.  #                                last update: 28/1/99 {10:32:48 pm} 
  8.  #  
  9.  # Reorganisation carried out by Vince Darley with much help from Tom 
  10.  # Fetherston, Johan Linde and suggestions from the Alpha-D mailing list.  
  11.  # Alpha is shareware; please register with the author using the register 
  12.  # button in the about box.
  13.  #  
  14.  # ###################################################################
  15.  ##
  16.  
  17. namespace eval flag {}
  18. namespace eval global {}
  19.  
  20. proc alpha::getGlobalPreferences {} {}
  21.  
  22.  
  23. ensureset tclvars {}
  24. ensureset allFlags {}
  25. ensureset allVars {}
  26. set invisibleModeVars(wordWrap) 1
  27.  
  28. proc flag::options {v} {
  29.     global flag::list
  30.     set thelist [set flag::list($v)]
  31.     set litems [lindex $thelist 1]
  32.     switch -- [lindex $thelist 0] {
  33.     "varitem" {
  34.         return [uplevel \#0 "set $litems"]
  35.     }
  36.     "varindex" {
  37.         return [uplevel \#0 "set $litems"]
  38.     }
  39.     "array" {
  40.         global $litems
  41.         return [lsort [array names $litems]]
  42.     }
  43.     }
  44.     return $litems
  45. }
  46.  
  47. catch {newPref linkflag lockStatus 1}
  48. # To scroll the horizontal scrollbar automatically to follow your typing, 
  49. # click this box||To enforce manual use of the horizontal scroll bar,
  50. # click this box.
  51. newPref linkflag autoHScroll 1
  52. # To save files automatically (except untitled buffers) every 'changesLim' 
  53. # changes, click this box||To disable the automatic saving of files, click
  54. # this box.
  55. newPref linkflag autoSave 0
  56. # To make the cursor blink, click this box||To stop the cursor blinking, 
  57. # click this box
  58. newPref linkflag blinkingCursor 1
  59. # To use a solid rectangular cursor, click this box||To use a thin vertical 
  60. # cursor, click this box.
  61. newPref linkflag blockCursor 0
  62. # To color words according to mode and context, click this box||To display all 
  63. # text more quickly, but in plain black and white, click this box.
  64. newPref linkflag coloring 1
  65. # To enable drag and drop editing using the mouse, click this box||To disable 
  66. # drag and drop editing using the mouse, click this box.
  67. newPref linkflag dragAndDrop 1
  68. # To display a horizontal scrollbar in new windows, click this box||To make 
  69. # maximum use of window space and not use a horizontal scrollbar, click this box.
  70. newPref linkflag horScrollBar 1
  71. # To enable clicking on hypertext items, click this box||To disable clicking
  72. # on hypertext items, click this box
  73. newPref linkflag hyperText 1
  74. # To force the insertion point to move with 'pageBack' and 'pageForward' 
  75. # commands, click this box||To leave the insertion point in place (usually 
  76. # offscreen) after 'pageBack' and 'pageForward' commands, click this box
  77. newPref linkflag moveInsertion 1
  78. # To list all file types (as opposed to just 'TEXT') in open/save dialog 
  79. # boxes, click this box||To display only 'TEXT' files in open/save dialog 
  80. # boxes, click this box.
  81. newPref linkflag openAllFiles 0
  82. # To make the window scroll dynamically while using vertical scrollbars, 
  83. # click this box||To make the window scroll only after releasing the button 
  84. # in a vertical scrollbar, click this box
  85. newPref linkflag powerThumb 1
  86. # Respect projector resources
  87. newPref linkflag projectorAware 1
  88. # To show all tabs, carriage returns, spaces etc with distinct symbols, 
  89. # click this box||To display whitespace characters normally, click this box.
  90. newPref linkflag showInvisibles 0
  91. # To use a small font for the various pop-up menus (e.g. marks menu), click this 
  92. # box||To use the standard system font for the popup menus, click this box.
  93. newPref linkflag smallMenuFont 1
  94. # if set, sorted is the default for function and section menus
  95. newPref linkflag sortedIsDefault
  96. # To allow tearing off of menus, click this box||To disable tearing-off of
  97. # menus, click this box
  98. newPref linkflag tearoffMenus 1
  99. # To enable Alpha's use of system temporary memory, click this box||To disallow
  100. # Alpha from using system temporary memory, click this box.
  101. newPref linkflag tempMem 1
  102. # To retain editing information to allow undo/redo operations, click this box||
  103. # To edit destructively (saving memory, and operating a little faster in, for 
  104. # example global replaces), click this box.
  105. newPref linkflag undoOn 1
  106. # To automatically insert a carriage-return when you exceed a line
  107. # length of 'fillColumn' characters, click this box||To disable automatic
  108. # text wrapping, click this box.
  109. newPref linkflag wordWrap 1
  110. # To add a description of each preference to the standard dialogs, click this 
  111. # box||To use standard preference dialogs, with a 'Help' button to display
  112. # descriptions, click this box
  113. newPref flag includeDescriptionsInDialogs 0
  114. # Used by completion routines: if there is a selection and you and
  115. # trying to complete something, and this item is set, Alpha will ask before 
  116. # deleting the selection.|| Used by completion routines: if there is a 
  117. # selection and you and trying to complete something, and this item is set, 
  118. # Alpha will ask before deleting the selection.
  119. newPref flag askDeleteSelection 0
  120. # To make a backup every time a file is saved, click this box||To save disk
  121. # space and not make backup copies when saving files, click this box.
  122. newPref flag backup 0
  123. # To force newly opened windows onto the main screen, click this box||To allow
  124. # new windows to be opened anywhere, including off screen, click this box.
  125. newPref flag forceMainScreen 1
  126. # To iconify windows when you switch to another application, click this box||
  127. # To leave windows alone when switching to other applications, click this box.
  128. newPref flag iconifyOnSwitch 0
  129. # To insert/remove spaces to ensure a single space between words when cutting
  130. # or pasting, click this box||To cut/paste precisely what is selected, click 
  131. # this box.
  132. newPref flag intelCutPaste 1
  133. # To sort the items in the popup function menu '{}', click this box||To leave
  134. # the items in the popup function menu '{}' in the order in which they appear,
  135. # click this box.
  136. newPref flag sortFuncsMenu 1
  137. # To place two spaces after the '.' at the end of each sentence when
  138. # filling blocks of text, click this box|| To place only a single space
  139. # after the '.' at the end of each sentence when
  140. # filling blocks of text, click this box
  141. newPref flag doubleSpaces 1
  142. # To print a header at the top of each printed page, click this box||
  143. # To print only the contents of the window, without any identifying header,
  144. # click this box.
  145. newPref flag printHeader 1
  146. # To include a file's full path in the printed header, click this box
  147. # ||To place just a file's name in the printed header, click this box
  148. newPref flag printHeaderFullPath 0
  149. # To include the current time in printed headers, click this box
  150. # ||To remove the current time from printed headers, click this box
  151. newPref flag printHeaderTime 1
  152. # To choose from a listbox of possible completions if you try to 
  153. # complete a command for which no unique
  154. # suffix exists, click this box.||To abort the completion if no
  155. # unique suffix exists, click this box.
  156. newPref flag listPickIfMultCmps 1
  157. # if we have a choice between, say \left, \leftRight, \leftMore,
  158. # then we don't get stuck on '\left' with this option.
  159. newPref flag listPickIfNonUniqueStuckCmp 1
  160. # To clear old marks automatically when you select 'Mark File', 
  161. # click this box.|| To check before clearing old marks, click this box.
  162. newPref flag quietlyClearMarks 1
  163. # Folder in which to store backups.  A null value tells Alpha to use
  164. # the file's current directory.
  165. newPref var backupFolder ""
  166. # Extension to add to files when backing them up
  167. newPref var backupExtension "~"
  168. # If the previous backup is more recent than this number of hours,
  169. # then don't make a new backup.  If greater than zero, this means the 
  170. # backups Alpha has tend to be significantly different to the current file.
  171. newPref var backupAgeRequirementInHours 0.0
  172. # When creating files for uploading through the Ftp menu, save them
  173. # with this eol format.  Note that some ftp clients may translate
  174. # eols for you as they up/download.
  175. newPref var createFtpType unix global "" "mac unix ibm"
  176. # Number of pixels from left edge of window to start of text
  177. newPref var horMargin 4
  178. # Alpha will visually indent code by this many characters to 
  179. # indicate its structure
  180. newPref var indentationAmount 4
  181. # If we have fewer than this many items in the opt-titlebar-menu,
  182. # add the contents of the current directory
  183. newPref var minItemsInTitlePopup 5
  184. # Used by 'Shift Left' and 'Shift Right' in the edit menu.
  185. newPref funnyChars shiftChar "\t"
  186. # The tiling items in the 'Arrange' menu will relocate this many
  187. # windows, starting with the front window and moving back.
  188. newPref var numWinsToTile 2
  189. newPref var tileHeight [expr {$screenHeight - 60}]
  190. newPref var tileLeft 2
  191. newPref var tileMargin 22
  192. newPref var tileProportion .60
  193. newPref var tileTop 40
  194. newPref var tileWidth [expr {$screenWidth - 10}]
  195. newPref linkvariable defLeft 2
  196. newPref linkvariable defTop 40
  197. newPref linkvariable defHeight $tileHeight
  198. newPref linkvariable defWidth [expr {$tileWidth > 510 ? 510 : $tileWidth}]
  199. # The fraction of the screen the small batch-search, or diff-style 
  200. # windows use up.
  201. newPref var batchListWindowFraction 0.25 global win::SetProportions
  202. # The type of keyboard you have.  This influences some of the keyboard
  203. # shortcuts Alpha places in the menus, and is used for better setting
  204. # of user-defined key-bindings.
  205. newPref variable keyboard US global keys::keyboardChanged keyboards array
  206. # This dictates the spelling Alpha uses for words like 'Colour/Color'
  207. newPref var spelling 0 global "" "American British" index
  208. # Useful for debugging some complex startup problems; you can choose
  209. # between logging all errors for later viewing, or displaying them
  210. # immediately
  211. newPref var reportErrors 1 global "" \
  212.   [list "Log startup errors" "Report errors immediately"] index
  213. # re-read internet preferences from IC each startup
  214. newPref flag synchroniseWithInternetConfig 0
  215. # The font to use for printing documents
  216. newPref linkvariable printerFont "" global "" "system monaco courier geneva helvetica profont times {new york}"
  217. # The font-size to use for printing documents.
  218. newPref linkvariable printerFontSize "" global "" "7 9 10 12 14 18"
  219. # Default font to use for new windows
  220. newPref linkvariable defaultFont "monaco" global "" "system monaco courier geneva helvetica profont times {new york} programmer"
  221. # Default font size to use for new windows
  222. newPref linkvariable fontSize 9 global "" "7 9 10 12 14 18"
  223. # The amount of information to store in the resource fork of saved text
  224. # files.  This can include font, tab, selection,... information.  Here, 'think' 
  225. # implies font, tab information, and 'mpw' adds window position and window
  226. # selection.
  227. newPref linkvariable savedState "" global "" "none think mpw"
  228. # The default size for a tab character for new windows (not the same as 
  229. # the amount of space used for visual indentation of code).
  230. # Alpha can be configured to remember tab sizes for previously edited documents
  231. # -- see 'savedState' for details.
  232. newPref linkvariable tabSize 8
  233. # Regexp used for automatic word wrapping
  234. newPref linkvariable wrapBreak {[\w_]+}
  235. # Regexp used for automatic word wrapping
  236. newPref linkvariable wrapBreakPreface {([^\w_])}
  237. # Auto-wrap if the user types further than this column
  238. newPref linkvariable wrapHigh ""
  239. # Auto-un-wrap if the user deletes chars so a line is shorter than this
  240. newPref linkvariable wrapLow ""
  241. # The maximum number of changes before auto-saving occurs (if set via the 
  242. # autoSave preference)
  243. newPref linkvariable changesLim ""
  244. # When wrapping text (see 'Word Wrap' preference), wrapping occurs
  245. # for any text beyond this column position.  Used by all 'Fill' routines
  246. newPref linkvariable fillColumn 75
  247. # Set to the regular expression that ALPHA uses to find function declarations.
  248. newPref linkvariable funcExpr {^[^ \t\(#\r/@].*\(.*\)$}
  249. # The parenthesised regexp block to use for the func name
  250. newPref linkvariable funcPar 1
  251. # Number of blanks left at beginning of lines by 'fill' routines.
  252. newPref linkvariable leftFillColumn 0
  253. # Alpha asks the user if wrapping should be done whenever the user opens 
  254. # files that have lines longer than 'paraColumn' characters
  255. newPref linkvariable paraColumn 180
  256. # Text column to use as the sort key when executing 'Sort Lines'.
  257. newPref linkvariable sortColumn 0
  258. # File to use for Tag searches.
  259. newPref linkio-file tagFile [file join $HOME cTAGS]
  260. # Margin size for printing
  261. newPref linkvariable leftMargin ""
  262. # Margin size for printing
  263. newPref linkvariable bottomMargin ""
  264. # Margin size for printing
  265. newPref linkvariable topMargin ""
  266. # Regular expression used to defines words for all internal operations.  Most
  267. # modes have their own definition of this variable.
  268. newPref linkvariable wordBreak {\w+}
  269. # Prepended to 'wordBreak' when looking backwards for a word.  Most
  270. # modes have their own definition of this variable.
  271. newPref linkvariable wordBreakPreface {(\W)}
  272. # Flags that won't appear in the menu.
  273. linkVar numLock
  274. # Usual place you use for downloading updates to Alpha and its packages.
  275. newPref var defaultAlphaDownloadSite "" global "" remote::site array
  276. # bug in alpha-IC interaction
  277. if {![catch "icGetPref DownloadFolder" res] && [file exists $res]} {
  278.     # Default download location for files from the internet
  279.     newPref var downloadFolder $res
  280. } else {
  281.     newPref var downloadFolder $HOME
  282. }
  283. # if first item = code, then indent relative to code by given value of second arg
  284. # if first item = fixed, then force indentation to given level
  285. set indentationTypes [list "code 0" "code 4" "fixed 0"]
  286.  
  287. lunion flagPrefs(Backups)         backup undoOn autoSave
  288. lunion varPrefs(Backups)         backupFolder backupExtension changesLim \
  289.   backupAgeRequirementInHours
  290. lunion flagPrefs(Gui)             blinkingCursor blockCursor coloring \
  291.   dragAndDrop iconifyOnSwitch intelCutPaste lockStatus showInvisibles \
  292.   smallMenuFont sortFuncsMenu tearoffMenus doubleSpaces hyperText
  293. lunion varPrefs(Gui)              defaultFont fontSize tabSize sortColumn
  294. lunion flagPrefs(Printer)         printHeader printHeaderFullPath printHeaderTime
  295. lunion varPrefs(Printer)         bottomMargin printerFont printerFontSize \
  296.   topMargin leftMargin
  297. lunion flagPrefs(Tags)         
  298. lunion varPrefs(Tags)             funcPar tagFile
  299. lunion flagPrefs(Window)         autoHScroll forceMainScreen horScrollBar \
  300.   moveInsertion powerThumb sortedIsDefault
  301. lunion varPrefs(Window)         defHeight defLeft defTop defWidth \
  302.   minItemsInTitlePopup savedState
  303. lunion flagPrefs(Tiling)         
  304. lunion varPrefs(Tiling)         numWinsToTile batchListWindowFraction horMargin \
  305.   tileHeight tileProportion tileLeft tileMargin tileTop tileWidth 
  306. lunion flagPrefs(Wrapping)     
  307. lunion varPrefs(Wrapping)         fillColumn leftFillColumn paraColumn wrapLow \
  308.   wrapHigh
  309. lunion flagPrefs(Electrics)     listPickIfMultCmps listPickIfNonUniqueStuckCmp \
  310.   askDeleteSelection
  311. lunion varPrefs(Electrics)     indentationAmount elecStopMarker
  312. lunion flagPrefs(Miscellaneous) 
  313. lunion flagPrefs(Helpers) 
  314. lunion varPrefs(Miscellaneous) 
  315. lunion varPrefs(Helpers) 
  316. lunion flagPrefs(WWW) synchroniseWithInternetConfig
  317. lunion varPrefs(WWW) defaultAlphaDownloadSite createFtpType downloadFolder \
  318.   browserSig ftpSig httpDownloadSig
  319. lunion flagPrefs(International)
  320. lunion varPrefs(International) keyboard spelling 
  321. lunion flagPrefs(Packages)
  322. lunion varPrefs(Packages) reportErrors
  323.  
  324. proc alpha::addToPreferencePage {page args} {
  325.     global varPrefs flagPrefs allFlags
  326.     set vars [lremove -l $args $allFlags]
  327.     set flags [lremove -l $args $vars]
  328.     eval lunion varPrefs($page) $vars
  329.     eval lunion flagPrefs($page) $flags
  330. }
  331.  
  332. namespace eval indent {}
  333.  
  334. set indent::amounts [list "nothing" "half-tab" "tab"]
  335.  
  336. proc indent::setup {args} {
  337.     global indent_amounts indentationAmount
  338.     set indent_amounts(0) 0
  339.     set indent_amounts(1) [expr {$indentationAmount/2}]
  340.     set indent_amounts(2) $indentationAmount
  341.     set indent_amounts(-1) [expr {-$indentationAmount/2}]
  342.     set indent_amounts(-2) [expr {-$indentationAmount}]
  343. }
  344. indent::setup
  345. trace variable indentationAmount w indent::setup
  346.  
  347. proc getFileSig {f} {
  348.     getFileInfo $f arr
  349.     if {[info exists arr(creator)]} {
  350.     return $arr(creator)
  351.     } else {
  352.     return ""
  353.     }
  354. }
  355.  
  356. proc getFileType {f} {
  357.     getFileInfo $f arr
  358.     if {[info exists arr(type)]} {
  359.     return $arr(type)
  360.     } else {
  361.     return "TEXT"
  362.     }
  363. }
  364.  
  365. # get defaults from internet config
  366. if {$synchroniseWithInternetConfig} {
  367.     catch {set browserSig [getFileSig [icGetPref -t 1 Helper•http]]}
  368.     catch {set ftpSig [getFileSig [icGetPref -t 1 Helper•ftp]]}
  369. } else {
  370.     catch {ensureset browserSig [getFileSig [icGetPref -t 1 Helper•http]]}
  371.     catch {ensureset ftpSig [getFileSig [icGetPref -t 1 Helper•ftp]]}
  372. }
  373.  
  374. # The application signature of your internet browser
  375. newPref v browserSig MOSS
  376. # The application signature of your ftp client
  377. newPref v ftpSig Arch
  378. # The application signature of your internet browser to use for downloading
  379. # only (rather than viewing)
  380. newPref v httpDownloadSig $browserSig
  381.  
  382. namespace eval win {}
  383.  
  384. proc win::SetProportions {} {
  385.     global tileHeight tileWidth tileTop tileLeft tileHeight \
  386.       errorHeight errorDisp tileMargin batchListWindowFraction
  387.     set errorHeight [expr {int ($batchListWindowFraction * ($tileHeight - $tileMargin))}]
  388.     set errorDisp [expr {int ((1- $batchListWindowFraction) * ($tileHeight - $tileMargin))}]
  389. }
  390.  
  391. proc wordWrapProc {val} { 
  392.     global mode wordWrap modifiedArrayElements 
  393.     global ${mode}modeVars
  394.     set wordWrap $val
  395.     set ${mode}modeVars(wordWrap) $val
  396.     lappend modifiedArrayElements [list wordWrap ${mode}modeVars]
  397. }
  398.  
  399.  
  400. proc toggleNumLock {} {
  401.     global numLock modifiedVars
  402.     
  403.     set numLock [expr {-1 * ($numLock - 1)}]
  404.     lappend modifiedVars numLock
  405. }
  406.  
  407. #============================================================================
  408. # declare these as modeVars in advance.  I'm not sure it is necessary (Vince)
  409. lunion modeVars funcExpr wrapBreakPreface wrapBreak wordBreakPreface wordBreak
  410.  
  411. # 'mode' is nothing when we start up.
  412. set mode             {}
  413. set lastMode            0
  414. set reverting             {}
  415.  
  416. # For quithook
  417. set modifiedVars        {}
  418. set modifiedArrVars     {}
  419. set modifiedModeVars    {}
  420. set modifiedArrayElements {}
  421.  
  422. namespace eval win {}
  423. ensureset win::Active ""
  424.  
  425.  
  426.  
  427.